Skip to content

fix(virtual-core): smooth scrolling for dynamic item sizes#1108

Merged
piecyk merged 5 commits intoTanStack:mainfrom
piecyk:fix/smooth-scrolling
Mar 6, 2026
Merged

fix(virtual-core): smooth scrolling for dynamic item sizes#1108
piecyk merged 5 commits intoTanStack:mainfrom
piecyk:fix/smooth-scrolling

Conversation

@piecyk
Copy link
Collaborator

@piecyk piecyk commented Jan 4, 2026

🎯 Changes

This PR enables reliable smooth scrolling in dynamic lists.

Nagranie.z.ekranu.2026-01-4.o.23.10.57.mov

Limitations

This approach assumes a virtualization strategy where the list is moved as a whole (for example via a single positional offset/translate, or by using before/after spacers).

Virtualization strategies that reposition individual items during scrolling may still show visible jitter or misalignment when smooth scrolling is combined with dynamic size updates, since item measurements are intentionally deferred while smooth scrolling is in progress.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • x ] I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

@changeset-bot
Copy link

changeset-bot bot commented Jan 4, 2026

🦋 Changeset detected

Latest commit: 132ea98

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@tanstack/virtual-core Patch
@tanstack/angular-virtual Patch
@tanstack/lit-virtual Patch
@tanstack/react-virtual Patch
@tanstack/solid-virtual Patch
@tanstack/svelte-virtual Patch
@tanstack/vue-virtual Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@nx-cloud
Copy link

nx-cloud bot commented Jan 4, 2026

View your CI Pipeline Execution ↗ for commit 132ea98

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 31s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 16s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-06 06:27:14 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 4, 2026

More templates

@tanstack/angular-virtual

npm i https://pkg.pr.new/@tanstack/angular-virtual@1108

@tanstack/lit-virtual

npm i https://pkg.pr.new/@tanstack/lit-virtual@1108

@tanstack/react-virtual

npm i https://pkg.pr.new/@tanstack/react-virtual@1108

@tanstack/solid-virtual

npm i https://pkg.pr.new/@tanstack/solid-virtual@1108

@tanstack/svelte-virtual

npm i https://pkg.pr.new/@tanstack/svelte-virtual@1108

@tanstack/virtual-core

npm i https://pkg.pr.new/@tanstack/virtual-core@1108

@tanstack/vue-virtual

npm i https://pkg.pr.new/@tanstack/vue-virtual@1108

commit: b473ffc

@piecyk piecyk force-pushed the fix/smooth-scrolling branch 3 times, most recently from a7382bb to 006a60c Compare January 7, 2026 21:30
@piecyk piecyk force-pushed the fix/smooth-scrolling branch from 006a60c to f880ca1 Compare March 5, 2026 21:06
@piecyk piecyk requested a review from Copilot March 5, 2026 21:13
@piecyk piecyk force-pushed the fix/smooth-scrolling branch from f32b62c to e5c43d0 Compare March 5, 2026 21:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make scrollTo*({ behavior: 'smooth' }) reliable in dynamic-size virtualized lists by introducing a scroll reconciliation loop and deferring some measurements during smooth scrolling.

Changes:

  • Add scrollState tracking + rAF-based reconciliation to keep a smooth-scroll target stable as item measurements update.
  • Defer ResizeObserver-driven measurements during smooth scrolling to a buffered range around the target.
  • Add a new React E2E “smooth-scroll” page and Playwright coverage for smooth scrolling scenarios.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/virtual-core/src/index.ts Adds scroll reconciliation state machine, measurement deferral during smooth scroll, and cancels pending rAF on cleanup.
packages/virtual-core/tests/index.test.ts Updates test window mock to include cancelAnimationFrame for the new cleanup path.
packages/react-virtual/e2e/app/vite.config.ts Registers smooth-scroll as an additional Vite build entrypoint for E2E.
packages/react-virtual/e2e/app/test/smooth-scroll.spec.ts Adds Playwright tests asserting smooth scrolling reaches expected targets/alignment.
packages/react-virtual/e2e/app/smooth-scroll/main.tsx New E2E app page demonstrating smooth scrolling with dynamic row heights.
packages/react-virtual/e2e/app/smooth-scroll/index.html HTML entry for the new E2E smooth scroll page.
examples/react/dynamic/src/main.tsx Updates the dynamic example to exercise smooth scrolling and initial “scroll to end”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@piecyk piecyk force-pushed the fix/smooth-scrolling branch from 06ecc66 to ead78b2 Compare March 5, 2026 21:54
@piecyk piecyk requested a review from Copilot March 5, 2026 21:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@piecyk piecyk merged commit be89e29 into TanStack:main Mar 6, 2026
4 checks passed
@github-actions github-actions bot mentioned this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants